Fixed flaky file-source unit tests #6984#6995
Merged
dlvenable merged 1 commit intoJul 21, 2026
Merged
Conversation
…lable executor (opensearch-project#6984) FileReader.readLoop and its backpressure/batch logic branched on System.currentTimeMillis(), so the max-read-time and drain-timeout tests depended on wall-clock timing. On a slow or loaded runner the loop could break before the first channel.read, leaving Mockito stubs unused and failing with UnnecessaryStubbingException. Inject a java.time.Clock into FileReader (public constructor defaults to Clock.systemDefaultZone(), package-private constructor accepts a Clock), matching the existing pattern in ServiceMapStatefulProcessor, OTelApmServiceMapProcessor, and PipelineShutdown. Tests now drive time with a mocked Clock: the read stub advances the fake clock past the deadline after delivering data once, so exactly one read happens deterministically. Removes all Thread.sleep and wall-clock assumptions from these tests. FileReaderPoolTest bookkeeping tests submitted readers to a real thread pool where the reader completed on a background thread and mutated the active/pending counts before the assertions ran. Add createPoolWithNonRunningExecutor so queueing, promotion, and close logic run synchronously. Tests that verify execution keep the real executor and await via verify(..., timeout(...)). Signed-off-by: Srikanth Padakanti <srikanth_padakanti@apple.com>
srikanthpadakanti
requested review from
KarstenSchnitter,
Zhangxunmt,
dinujoh,
divbok,
dlvenable,
graytaylor0,
kkondaka,
oeyh,
san81,
sb2k16 and
srikanthjg
as code owners
July 14, 2026 17:00
lawofcycles
approved these changes
Jul 19, 2026
lawofcycles
left a comment
Contributor
There was a problem hiding this comment.
Looks good, thanks for taking this on. The injected Clock and non running executor make the tests deterministic. LGTM.
kkondaka
approved these changes
Jul 21, 2026
dlvenable
approved these changes
Jul 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The tests relied on wall-clock timing and background threads, so they passed locally but failed randomly on CI. I made them deterministic:
No product behavior change; the default clock is still the system clock.
Issues Resolved
Resolves #6984
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.